package ru.jetsoft.reg112.desktop.control;

import javafx.scene.control.ComboBox;
import ru.jetsoft.reg112.desktop.DataFormatException;
import ru.jetsoft.reg112.desktop.data.DicCache;
import ru.jetsoft.reg112.desktop.data.Param;

public class DicControl extends InputParamControl {

    private final ComboBox<String> comboBox;

    public DicControl(Param param) throws DataFormatException {
        super(param);
        comboBox = new ComboBox<>();
        comboBox.getItems().addAll(DicCache.getDicValues(param.getType()));
        getHBox().getChildren().add(comboBox);
    }

    @Override
    public String getValue() {
        String selected = comboBox.getValue();
        try {
            Integer id = DicCache.getDicId(getParam().getType(), selected);
            return id.toString();
        } catch(DataFormatException ex) {
            return null;
        }
    }
}
